/**
 * 
 */
package by.imotaeva.printing_services.services.impl;

import javax.annotation.PostConstruct;
import javax.inject.Inject;

import org.apache.commons.lang3.Validate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import by.imotaeva.printing_services.dataaccess.CustomerIdentificationDao;
import by.imotaeva.printing_services.datamodel.Customer;
import by.imotaeva.printing_services.datamodel.CustomerIdentification;
import by.imotaeva.printing_services.services.CustomerIdentificationService;

/**
 * @author Inna
 *
 */
@Service
public class CustomerIdentificationServiceImpl implements
		CustomerIdentificationService {
	private static final Logger LOGGER = LoggerFactory
			.getLogger(CustomerIdentificationServiceImpl.class);

	@PostConstruct
	private void init() {
		// this method will be called by Spring after bean instantiation. Can be
		// used for any initialization process.
		LOGGER.info(
				"Instance of CustomerIdentificationService is created. Class is: {}",
				getClass().getName());
	}

	@Inject
	private CustomerIdentificationDao dao;

	@Override
	public void createNewCustomerIdent(Customer customer,
			CustomerIdentification customerIdentification) {
		Validate.isTrue(
				customerIdentification.getId() == null,
				"This method should be called for 'not saved yet' customerIdentification only. Use UPDATE instead");
		customerIdentification.setCustomer(customer);
		dao.insert(customerIdentification);
	}

	@Override
	public void updateCustomerIdentification(
			CustomerIdentification customerIdentification) {
		dao.update(customerIdentification);
	}

	@Override
	public CustomerIdentification get(Long id) {
		CustomerIdentification entity = dao.getById(id);
		return entity;
	}

	@Override
	public void delete(CustomerIdentification entity) {
		LOGGER.debug("Remove: {}", entity);
		dao.delete(entity.getId());

	}

	@Override
	public void deleteAll() {
		LOGGER.debug("Remove all CustomerIdentification");
		dao.deleteAll();

	}

}
